﻿using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Xna.Framework;

namespace Daybreak.Core.SceneGraph
{
    /// <summary>
    /// General group node which maintains a list of children. 
    /// </summary>
    public class Group : Node
    {
        protected List<Node> _children = new List<Node>();

        public Group()
        {
        }

        public override void Accept(NodeVisitor visitor)
        {
            visitor.VisitGroup(this);
        }

        public override void ComputeBound(ref BoundingBox result)
        {
            for (int i = 0; i < _children.Count; i++)
                _children[i].ComputeBound(ref result);
        }

        public void AddChild(Node child)
        {
            _children.Add(child);
        }

        public bool Contains(Node child)
        {
            if (FindChildIndex(child) == -1)
                return false;

            return true;
        }

        public int FindChildIndex(Node child)
        {
            return _children.IndexOf(child);
        }

        public void RemoveChild(Node child)
        {
            _children.Remove(child);
        }

        public override string ToString()
        {
            return "Childs:" + _children.Count;
        }

        public Node this[int index]
        {
            get { return _children[index]; }
            set { _children[index] = value; }
        }

        public int ChildrenCount
        {
            get { return _children.Count; }
        }
    }
}
